/*
 * Copyright 2006 Kevin Wetzels 
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); 
 * you may not use this file except in compliance with the License. 
 * You may obtain a copy of the License at 
 * 
 *       http://www.apache.org/licenses/LICENSE-2.0 
 *       
 * Unless required by applicable law or agreed to in writing, software 
 * distributed under the License is distributed on an "AS IS" BASIS, 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 * See the License for the specific language governing permissions and 
 * limitations under the License.
 */
package be.roam.drest.service.youtube.xml;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

import org.xml.sax.SAXException;

import be.roam.drest.service.youtube.YouTubeUserProfile;
import be.roam.drest.service.youtube.YouTubeVideo;
import be.roam.drest.xml.SaxParser;

/**
 * Class centralizing the parsing of YouTube XML responses.
 */
public class YouTubeXmlParser extends SaxParser {

    /**
     * Parses a user profile.
     * 
     * @param inputStream input stream containing the user profile in XML format.
     * 
     * @return the user profile
     * 
     * @throws IOException
     * @throws SAXException
     */
    public static YouTubeUserProfile parseUserProfile(InputStream inputStream) throws IOException, SAXException {
        YouTubeUserProfileHandler userProfileHandler = new YouTubeUserProfileHandler();
        parse(inputStream, userProfileHandler);
        return userProfileHandler.getUserProfile();
    }

    /**
     * Parses a video list XML.
     * 
     * @param inputStream input stream containing the video list
     * 
     * @return list of videos
     * 
     * @throws IOException
     * @throws SAXException
     */
    public static List<YouTubeVideo> parseVideoList(InputStream inputStream) throws IOException, SAXException {
        YouTubeVideoHandler videoHandler = new YouTubeVideoHandler();
        parse(inputStream, videoHandler);
        return videoHandler.getVideoList();
    }

    /**
     * Parses a friend list.
     * 
     * @param inputStream input stream containing the friend list.
     * 
     * @return list of friends
     * 
     * @throws IOException
     * @throws SAXException
     */
    public static List<YouTubeUserProfile> parseFriendList(InputStream inputStream) throws IOException, SAXException {        
        YouTubeFriendHandler friendHandler = new YouTubeFriendHandler();
        parse(inputStream, friendHandler);
        return friendHandler.getFriendList();
    }

}
